/**
 * Copyright 2013 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.viettel.core.common.utils;

import java.lang.reflect.Array;
import java.util.List;

/**
 * Mo ta muc dich cua lop (interface)
 * 
 * @author: ToanTM1
 * @version: 2.1
 * @since: 19-09-2013 - 16:12:56
 */
public class ArrayUtil {

	@SuppressWarnings("unchecked")
	public static <T> T[] listToArray(List<T> list, Class<T> clazz) {
		/**** Null Checks removed for brevity ****/
		T[] arr = (T[]) Array.newInstance(clazz, list.size());

		for (int i = 0; i < list.size(); ++i) {
			arr[i] = list.get(i);
		}
		return arr;
	}

	@SuppressWarnings("unchecked")
	public <T> T[][] multiListToArray(final List<List<T>> listOfList, final Class<T> classz) {
		final T[][] array = (T[][]) Array.newInstance(classz, listOfList.size(), 0);

	    for (int i = 0; i < listOfList.size(); i++) {
	        array[i] = listOfList.get(i).toArray((T[]) Array.newInstance(classz, listOfList.get(i).size()));
	    }

	    return array;
	}
}
